package com.example.b_308.myapplication.view.main.Base;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.b_308.myapplication.R;
import com.example.b_308.myapplication.model.been.MessageBeen;

import java.util.List;

/**
 * Created by B-308 on 2017/11/22.
 */
public class MessageAdapter extends BaseLvAdapter implements View.OnClickListener {
    List<MessageBeen> messageBeenList;
    LayoutInflater inflater;
    Context context;
    public void notifyChango(List<MessageBeen> messageBeens){
        this.messageBeenList = messageBeens;
        notifyDataSetChanged();

    }

    public MessageAdapter(List<MessageBeen> messageBeenList, Context context) {
        this.messageBeenList = messageBeenList;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return messageBeenList.size();
    }

    @Override
    public MessageBeen getItem(int position) {
        return messageBeenList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(null == convertView){
            convertView = inflater.inflate(R.layout.item_message,null,false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv_message.setText(getItem(position).getStaff().getName());
        convertView.setOnClickListener(this);
        return convertView;
    }

    @Override
    public void onClick(View v) {

    }

    class ViewHolder{
        View contentView;
        TextView tv_message;

        public ViewHolder(View contentView){
            this.contentView = contentView;
            tv_message = (TextView) contentView.findViewById(R.id.tv_message);
        }
    }
}
